<template>
  <div>
    <!-- table -->
    <!-- 旧件回运仓库维护-按下线工厂 - 旧件回运仓库维护-按下线工厂新增 -->
    <FormPanel ref="formPanel" :list="formList" :cols="1" :formType="'add'" labelWidth="110" :isSubmitBtn="false" @formChange="formChangeHandle" />
    <div style="margin-bottom: 1rem;"></div>
      <template slot="controls" slot-scope="props">
        <multiuse-button size="small" type="primary" icon="el-icon-plus" @click="add()">添加</multiuse-button>
      </template>
    <div style="padding-top: 3rem;"></div>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <multiuse-button type="primary" :click="saveDialog.bind()">保存</multiuse-button>
      <multiuse-button type="primary" @click="closeDialog">关 闭</multiuse-button>
    </div>
    <BaseDialog :visible.sync="FactoryVisible" :title="'工厂选择'" destroyOnClose width="850px" :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}">
      <FactoryVehicle @close="factoryClose" @save="factorySave"></FactoryVehicle>
    </BaseDialog>
    <BaseDialog :visible.sync="WarehouseVisible" :title="'仓库选择'" destroyOnClose width="850px" :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}">
      <WarehouseVehicle @close="warehouseClose" @save="warehouseSave"></WarehouseVehicle>
    </BaseDialog>
  </div>
</template>
<script>
import FactoryVehicle from "@/pages/claimDemage/tools/FactoryVehicle";
import WarehouseVehicle from './WarehouseVehicle.vue';
import { newSave} from '@/api/claim/factory/ReturnWhMaintainFactory';

export default {
  // mixins: [dictionary],
  components: {
    FactoryVehicle,
    WarehouseVehicle
  },
  data() {
    return {
      FactoryVisible: false,
      WarehouseVisible: false,
      collapse: false,
      infoId: null,
      // topFilterInit: this.topFilterInitFun(),
      // fetchApi: getUser,
      fetchParams: {}, //ipa 接口
      selectedRows: [], //选中经销商
      formList: this.createFormList(),
      saveData: null
    };
  },
  created() {
  },
  methods: {
    createFormList() {
      return [
        {
          type: 'INPUT',
          label: '仓库代码',
          fieldName: 'whCode',
          placeholder: '请选择仓库代码',
          rules: [{required: true, message: '请选择仓库代码', trigger: 'change'}],
          unitRender: p => {
            return (
              <div>
                <multiuse-button icon="el-icon-search" onClick={() => this.warehouseTurnOn()}/>
              </div>
            );
          }
        },
        {
          type: 'INPUT',
          label: '仓库名称',
          fieldName: 'whName',
          rules: [{required: true, message: '请输入仓库名称', trigger: 'change'}],
        },
        {
          type: 'INPUT',
          label: '工厂代码',
          fieldName: 'facCode',
          placeholder: '请选择工厂代码',
          rules: [{required: true, message: '请选择工厂代码', trigger: 'change'}],
          unitRender: p => {
            return (
              <div>
                <multiuse-button icon="el-icon-search" onClick={() => this.factoryTurnOn()}/>
              </div>
            );
          }
        },
        {
          type: 'INPUT',
          label: '工厂名称',
          fieldName: 'facName',
          rules: [{required: true, message: '请输入工厂名称', trigger: 'change'}],
        },
        {
          type: 'SELECT',
          label: '状态',
          fieldName: 'wfStatus',
          placeholder: '请选择状态',
          itemList: [{text: '热点', value: '1'}, {text: '资讯', value: '2'}],
          rules: [{required: true, message: '请选择状态', trigger: 'change'}],
        }
      ];
    },
    formChangeHandle(val) {
      console.log(val);
      this.saveData = val;
    },
    //搜索获取数据
    changeHandle(val) {
      this.fetchParams = val;
      console.log(val);
    },
    //选中
    selectChange(rows) {
      this.selectedRows = rows;
      console.log(this.selectedRows);
    },
    //保存
    async saveDialog() {
      this.$refs.formPanel.SUBMIT_FORM();
      if (this.saveData !== null) {
        let res = await newSave(this.saveData);
        console.log(res);
        if (res.resultCode === 200) {
          this.closeDialog('refresh');
          return this.$notify.success({ title: '提示信息', message: '保存成功' });
        } else {
          this.$notify.error({ title: '提示信息', message: res.errMsg || '保存失败!' });
          this.closeDialog();
        }
      } else {
        return this.$notify.warning({ title: '提示信息', message: '有未校验通过的信息' });
      }
    },
    //取消操作
    closeDialog() {
      this.$emit('close', {visible: false, data: this.selectedRows, type: 'close'});
    },
    factoryTurnOn() {
      this.FactoryVisible = true;
    },
    warehouseTurnOn() {
      this.WarehouseVisible = true;
    },
    factoryClose(){
      this.FactoryVisible = false;
    },
    warehouseClose(){
      this.WarehouseVisible = false;
    },
    factorySave(obj) {
      this.formList.find(x => x.fieldName == 'facCode').initialValue = obj[0].address;
      this.FactoryVisible = false;
    },
    warehouseSave(obj) {
      this.formList.find(x => x.fieldName == 'whCode').initialValue = obj[0].address;
      this.WarehouseVisible = false;
    },
    add() {
    }
  }
};
</script>

<style lang="less" scoped></style>
